package com.ymatou.iapi.sellercs.testcase;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.sellercs.parameter.GetStatusBean;
import com.ymatou.iapi.sellercs.service.GetStatusCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.SellerCSIMCallService;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
/**
*获取子客服状态
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetStatus{
	private static GetStatusBean getstatusBean;
	private static GetStatusCall getstatusCall;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
	private static int zsellerId = Integer.parseInt(EnvSetup.getData("autotest_seller_z"));
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取子客服状态");
	}

	@Before
	public void caseUp() throws ClientProtocolException, IOException {
		getstatusBean=new GetStatusBean();
		getstatusCall=new GetStatusCall();
		SellerCSIMCallService.OffLine(sellerId, null);
		SellerCSIMCallService.OffLine(zsellerId, null);
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getstatusCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetStatus_001() {
		Logger.start(true,"获取子客服状态成功在线,在线");
		try {
			SellerCSIMCallService.AppLogin(sellerId);
			SellerCSIMCallService.OnLine(sellerId);
			Thread.sleep(1000);
			getstatusBean.setCSId(sellerId);
			getstatusCall.setData(getstatusBean);
			getstatusCall.callService();			
			Logger.verifyIsContains("200", getstatusCall.getString("Status"), "验证Status");	
			Logger.verifyEquals(0, getstatusCall.getJsonObject().get("Result").getAsJsonObject().get("Status").getAsInt(), "验证在线");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetStatus_002() {
		Logger.start(true,"不输入csid失败");
		try {
			getstatusCall.setData(getstatusBean);
			getstatusCall.callService();			
			Logger.verifyIsContains("400", getstatusCall.getString("Status"), "验证Status");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetStatus_003() {
		Logger.start(true,"获取子客服状态成功在线,离线");
		try {
			SellerCSIMCallService.AppLogin(sellerId);
			SellerCSIMCallService.LeaveLine(sellerId);
			Thread.sleep(1000);
			getstatusBean.setCSId(sellerId);
			getstatusCall.setData(getstatusBean);
			getstatusCall.callService();			
			Logger.verifyIsContains("200", getstatusCall.getString("Status"), "验证Status");	
			Logger.verifyEquals(1, getstatusCall.getJsonObject().get("Result").getAsJsonObject().get("Status").getAsInt(), "验证在线");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetStatus_004() {
		Logger.start(true,"获取子客服状态成功在线,下线");
		try {
			SellerCSIMCallService.AppLogin(sellerId);
			SellerCSIMCallService.OffLine(sellerId,null);
			Thread.sleep(1000);
			getstatusBean.setCSId(sellerId);
			getstatusCall.setData(getstatusBean);
			getstatusCall.callService();	
			Logger.verifyIsContains("200", getstatusCall.getString("Status"), "验证Status");	
			Logger.verifyEquals(-1, getstatusCall.getJsonObject().get("Result").getAsJsonObject().get("Status").getAsInt(), "验证在线");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetStatus_005() {
		Logger.start(true,"获取子客服状态成功在线,pc在线");
		try {
			String SocketIoToken= TestDataManager.getRandomUUID().toString();
			SellerCSIMCallService.PcLogin(sellerId, sellerId,SocketIoToken);
			SellerCSIMCallService.OnLine(sellerId);
			Thread.sleep(1000);
			getstatusBean.setCSId(sellerId);
			getstatusCall.setData(getstatusBean);
			getstatusCall.callService();			
			Logger.verifyIsContains("200", getstatusCall.getString("Status"), "验证Status");	
			Logger.verifyEquals(0, getstatusCall.getJsonObject().get("Result").getAsJsonObject().get("Status").getAsInt(), "验证在线");
			SellerCSIMCallService.OffLine(sellerId, SocketIoToken);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetStatus_006() {
		Logger.start(true,"获取子客服状态成功在线,pc离线");
		try {
			String token= TestDataManager.getRandomUUID().toString();
			SellerCSIMCallService.PcLogin(sellerId, sellerId,token);
			SellerCSIMCallService.LeaveLine(sellerId);
			Thread.sleep(1000);
			getstatusBean.setCSId(sellerId);
			getstatusCall.setData(getstatusBean);
			getstatusCall.callService();			
			Logger.verifyIsContains("200", getstatusCall.getString("Status"), "验证Status");	
			Logger.verifyEquals(1, getstatusCall.getJsonObject().get("Result").getAsJsonObject().get("Status").getAsInt(), "验证在线");
			SellerCSIMCallService.OffLine(sellerId, token);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetStatus_007() {
		Logger.start(true,"获取子客服状态成功在线,pc下线");
		try {
			String token=TestDataManager.getRandomUUID().toString();
			SellerCSIMCallService.PcLogin(sellerId, sellerId,token);
			SellerCSIMCallService.OffLine(sellerId, token);
			Thread.sleep(1000);
			getstatusBean.setCSId(sellerId);
			getstatusCall.setData(getstatusBean);
			getstatusCall.callService();			
			Logger.verifyIsContains("200", getstatusCall.getString("Status"), "验证Status");	
			Logger.verifyEquals(-1, getstatusCall.getJsonObject().get("Result").getAsJsonObject().get("Status").getAsInt(), "验证在线");
			SellerCSIMCallService.OffLine(sellerId, token);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}